// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
 * RecursiveDescentClassVisitor.h
 *
 *  Created on: Dec 6, 2009
 *      Author: dhovemey
 */

#ifndef RECURSIVEDESCENTCLASSVISITOR_H_
#define RECURSIVEDESCENTCLASSVISITOR_H_

#include "vm/IClassVisitor.h"

/**
 * Base class for visitors that recursively visit all of the features
 * of a Class.
 */
class RecursiveDescentClassVisitor : public IClassVisitor {
private:
	RecursiveDescentClassVisitor(const RecursiveDescentClassVisitor &);
	RecursiveDescentClassVisitor& operator=(const RecursiveDescentClassVisitor &);

public:
	/** Constructor. */
	RecursiveDescentClassVisitor();
	/** Destructor. */
	virtual ~RecursiveDescentClassVisitor();

	virtual void visitClass(Class *cls);
	virtual void visitConstantPool(ConstantPool *cp);
	virtual void visitConstantString(ConstantString *c);
	virtual void visitConstantSymbol(ConstantSymbol *c);
	virtual void visitConstantClass(ConstantClass *c);
	virtual void visitConstantI32(ConstantInt32 *c);
	virtual void visitConstantBoolean(ConstantBoolean *c);
	virtual void visitField(Field *field);
	virtual void visitMethod(Method *method);
	virtual void visitInstruction(uint16_t offset, Opcode opcode);
	virtual void visitCPInstruction(uint16_t offset, Opcode opcode, uint16_t cpIndex);
	virtual void visitI8Instruction(uint16_t offset, Opcode opcode, int8_t i8);
	virtual void visitCPI8Instruction(uint16_t offset, Opcode opcode, uint16_t cpIndex, int8_t i8);
	virtual void visitBranchInstruction(uint16_t offset, Opcode opcode, uint16_t branchOffset);

private:
	uint16_t unpackCodeShort(int &offset, const uint8_t *code, int numBytes);
};

#endif /* RECURSIVEDESCENTCLASSVISITOR_H_ */
